package com.itheima.tliasproject.controller;

import com.itheima.tliasproject.mapper.StudentMapper;
import com.itheima.tliasproject.pojo.PageResult;
import com.itheima.tliasproject.pojo.Result;
import com.itheima.tliasproject.pojo.Student;
import com.itheima.tliasproject.pojo.StudentQueryParam;
import com.itheima.tliasproject.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;


    //分页查询学生信息
    @GetMapping("/students")
    public Result getAllstu(StudentQueryParam studentQueryParam){
        log.info("接收到的数据是 ：{}",studentQueryParam);
        PageResult liststu = studentService.getAll(studentQueryParam);
        return Result.Success(liststu);
    }
    //删除学员
    @DeleteMapping("/students/{ids}")
    public Result deleteids(@PathVariable List<Integer> ids){
        log.info("接收到的数据是：{}",ids);
        studentService.delete(ids);
        return Result.Success();
    }

    //新增学员
    @PostMapping("/students")
    public Result Save(@RequestBody Student student){
        log.info("接收到的数据是：{}",student);
        studentService.save(student);
        return Result.Success();
    }

    //根据id查看学员信息
    @GetMapping("/students/{id}")
    public  Result selectById(@PathVariable Integer id){
        log.info("接收到的查询id数据是：{}",id);
        Student student = studentService.selectById(id);
        return Result.Success(student);
    }

    //修改学员
    @PutMapping("/students")
    public Result upDate(@RequestBody Student student){
        log.info("接收到的参数是 ：{} ",student);
        studentService.update(student);
        return Result.Success();
    }

    //违纪处理
    @PutMapping("/students/violation/{id}/{score}")
    public Result UpdateByscore(@PathVariable Integer id,@PathVariable Integer score){
        log.info("接收到的数据是 id:{}，score:{}",id,score);
        studentService.updateByscore(id,score);
        return Result.Success();
    }

}

